<template>
  <div>
    <el-row :gutter="20">
      <!--      机构信息-->
      <el-col :span="6">
        <el-card class="box-card" style="height: 800px">
          <el-tree :data="list" :props="defaultProps" @node-click="handleNodeClick" ></el-tree>
        </el-card>
      </el-col>

      <!--      新增机构提示-->
      <el-col :span="18" v-if="orgId == ''">
        <el-card class="box-card" style="height: 800px">
          <el-col :sm="12" :lg="6">
            <el-result icon="warning" title="警告提示" subTitle="请选择机构">
              <template slot="extra">
              </template>
            </el-result>
          </el-col>
        </el-card>
      </el-col>

<!--      定时任务日志数据-->
      <el-col :span="18" v-if="orgId != ''">
        <el-card class="box-card" style="height: 800px">
          <el-table v-loading="loading" :data="tableData" style="width: 100%">
            <el-table-column
              width="120"
              label="序号">
              <template slot-scope="scop">
                <!--            queryVo.pageNum 当前页
                            queryVo.pageSize 页大小-->
                {{scop.$index+(pagenum - 1) * pagesize + 1}}
              </template>
            </el-table-column>
            <el-table-column prop="jobId" label="任务编号">

            </el-table-column>
            <el-table-column prop="beanName" label="任务名称">

            </el-table-column>
            <el-table-column prop="params" label="优先级">

            </el-table-column>
            <el-table-column prop="status" label="状态">

            </el-table-column>
            <el-table-column prop="times" label="耗时(毫秒)">

            </el-table-column>
            <el-table-column prop="createDate" label="执行时间">

            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import os from '../../../../src/api/logisticsmanagement/organization/organizationScope'
import method from '../../../api/logisticsmanagement/schedulingmanagement/schedulingInformation'

  export default {
    name: "schedulingInformation",
    data() {
      return{
        //  当前页
        pagenum: 1,
        //  一页显示几条数据
        pagesize: 5,
        //  总页数
        pagesum: 0,
        //  查询出来的数据
        tableData: null,
        //机构树
        list:[],
        // 设置树，名字，子集合
        defaultProps: {
          children: 'orgTreeDtoList',
          label: 'name'
        },
        //  当前机构ID
        orgId: "",
        // 你选择的机构的信息
        setLatLng:{
          id: ""
        },
        // 查询树的条件
        data:{},
        //  定时任务表格加载状态
        loading: false,
      }
    },
    methods: {
      //  根据机构id分页查询定时任务日志
      pageFindJobLogByOrgId(orgId) {
        method.pageFindJobLogByOrgId(this.pagenum,this.pagesize,orgId).then(({data}) => {
          if(data.code == 200){
            if(data.data.records != null && data.data.records != ""){
              this.tableData = data.data.records
              console.log(this.tableData)
            }else{
              this.tableData = null
            }
          }
          this.$store.commit("startAnimation",false);
        })
      },
      //  点击机构触发
      handleNodeClick(obj) {
        this.orgId = obj.orgId
        this.$store.commit("startAnimation",true);
        this.pageFindJobLogByOrgId(obj.pdCoreOrg.id)
      },
      // 获取机构树
      getTree(){
        os.queryCoreOrgAllInfo(this.data).then(({data})=>{
          this.dg (data.data)
          this.list = data.data
        })
      },
      // 递归设置机构名称
      dg (data) {
        if(data!=null){
          for (var i = 0; i < data.length; i++) {
            if (data[i].orgTreeDtoList.length > 0) {
              this.dg(data[i].orgTreeDtoList)
            }
            this.$set(data[i], 'name', data[i].pdCoreOrg.name)
          }
        }
      },
    },
    created() {
      this.getTree()
    }
  }
</script>
<style>
.map {
  width: 100%;
  height: 550px;
}
</style>
